var HuaZi = {
    name: 'huazi',
    age: 20,
    sex: 'boy',
    smoke: function(){
    console.log('somkeing cool');
    this.health--
    },
    drink: function(){
   console.log('drink good');
   this.health++
    },
    health: 100
}

// HuaZi.health++ //可读可写

// console.log(HuaZi.health);
// HuaZi.smoke()
// HuaZi.drink()
// HuaZi.drink()
// console.log(HuaZi.health);

//增
HuaZi.boyFriend = 'lai'

// //查
// console.log(HuaZi.boyFriend);

// //改
// HuaZi.sex = 'girl'
// console.log(HuaZi.sex);

//删
delete HuaZi.sex
delete HuaZi.name
//console.log(HuaZi.name); //undefined ?

//当访问一个不存在的变量时会报错，当访问一个对象中不存在的属性就为undefined！为什么？



// 对象的创建
// 1.  var obj = {} //plainObject 对象字面量
// 2.  构造函数
    // 1）系统自带的构造函数 Object()
    // 2）自定义

// var obj = new Object() //var obj = {} 没有区别
// obj.name = 'mincheng'
// obj.sex = 'boy'
// console.log(obj);


// 2)
function Car(color){
    this.name = 'BMW'
    this.height = '1400'
    this.lang = '4900'
    this.weight = 1000

    this.health = 100
    this.run = function(){
        this.health--
    }
    this.color = color
}

var car1 = new Car('pink')
var car2 = new Car('red')

//console.log(car1 == car2);//构造函数实例化出来的对象是相互独立的
// console.log(car1, car2);


car1.name = '红旗'
car2.name = 'jeep'

car2.run()
console.log(car1);
console.log(car2);